/*
 * Copyright 2007-2010 Jeremy Brown.
 *
 * Licensed under the Apache License, Version 2.0 (the "License")
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @author <a href="http://jeremy-brown.com">Jeremy Brown</a>
 */

package groovy.prefuse.demos

import java.awt.geom.Point2D

import prefuse.*
import prefuse.action.*
import prefuse.action.assignment.*
import prefuse.action.layout.graph.*
import prefuse.activity.*
import prefuse.controls.*
import prefuse.data.*
import prefuse.render.*
import prefuse.util.*
import prefuse.visual.*

import groovy.swing.*
import groovy.prefuse.*
import groovy.prefuse.factory.*

def swing = new PrefuseBuilder()

def group = "tree"

def frame = swing.frame(title:'Tree Demo 1', defaultCloseOperation:javax.swing.WindowConstants.EXIT_ON_CLOSE)
{
	pfTree(id:"tree", columnNames:["name"], columnTypes:[String])
	{
		pfNode(["Russ & Judy"])
		{
			pfNode(["Jeremy & Sara"])
			pfNode(name:"Gabe & Sarah")
			{
				pfNode(name:"Benjamin")
				pfNode("Bekka")
			}
			pfNode(name:"Noah & Laura")
			{
				pfNode("Sierra")
				{
					pfNode("Flea")
					{
						pfNode("Flea B")
						pfNode("Flea C")
						pfNode("Flea D")
						pfNode("Flea E")
						pfNode("Flea F")
					}
					pfNode("Tic")
					{
						pfNode("Tic 2")
						pfNode("Tic 3")
						pfNode("Tic 4")
					}
				}
			}
		}
	}
	
	pfVisualization(id:"vis")
	{
		pfTree(tree, group:group)
		
		pfLabelRenderer(forNode:true, textField:"name", roundedCorner:[8,8], 
			align:Constants.LEFT,
			renderType:AbstractShapeRenderer.RENDER_TYPE_FILL)
			
		pfEdgeRenderer(forEdge:true, edgeType:Constants.EDGE_TYPE_CURVE, 
			align1:Constants.RIGHT, align2:Constants.LEFT,
			valign1:Constants.CENTER, valign2:Constants.CENTER)
		
		pfLayout(NodeLinkTreeLayout, id:"treeLayout", name:"treeLayout", group:group, orientation:Constants.ORIENT_LEFT_RIGHT, 
			depthSpacing:50d, breadthSpacing:20d, subtreeSpacing:20d, 
			layoutAnchor:new Point2D.Double(50,200))
			
		pfColorAction(group:"tree.nodes", id:"textColor", name:"textColor", field:VisualItem.TEXTCOLOR, defaultColor:[0,0,0])
		pfColorAction(group:"tree.nodes", id:"nodeColor", name:"nodeColor", field:VisualItem.FILLCOLOR, defaultColor:[190,190,255])
		pfColorAction(group:"tree.edges", id:"edgeColor", name:"edgeColor", field:VisualItem.STROKECOLOR, defaultColor:[200,200,200])
		
		pfActionList(id:"draw", name:"draw")
		{
			pfLayout(treeLayout)
			pfAction(textColor)
			pfAction(nodeColor)
			pfAction(edgeColor)
		}
		
	}
	
	pfDisplay(id:"display", visualization:vis, size:[720, 500], highQuality:true)
	{
		pfControl(DragControl)
		pfControl(PanControl)
		pfControl(ZoomControl)
	}
}


frame.pack()
frame.show()
swing.vis.run("draw")
